home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-06 | 37.1 KB | 1,149 lines |
- Newsgroups: comp.sources.misc
- From: dan%step.uucp@uunet.uu.net (Daniel Weaver)
- Subject: v25i032: ted - Terminfo/termcap test program, Part07/07
- Message-ID: <1991Nov6.043050.6192@sparky.imd.sterling.com>
- X-Md4-Signature: a08ed78b26258c5d417418d71a69a582
- Date: Wed, 6 Nov 1991 04:30:50 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: dan%step.uucp@uunet.uu.net (Daniel Weaver)
- Posting-number: Volume 25, Issue 32
- Archive-name: ted/part07
- Environment: UNIX
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # If this archive is complete, you will see the following message at the end:
- # "End of archive 7 (of 7)."
- # Contents: bsd.h capcomp.c color.c makefile
- # Wrapped by dan@step on Fri Nov 1 11:28:29 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'bsd.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'bsd.h'\"
- else
- echo shar: Extracting \"'bsd.h'\" \(7528 characters\)
- sed "s/^X//" >'bsd.h' <<'END_OF_FILE'
- X/*
- X** This software is Copyright (c) 1991 by Daniel Weaver.
- X**
- X** Permission is hereby granted to copy, distribute or otherwise
- X** use any part of this package as long as you do not try to make
- X** money from it or pretend that you wrote it. This copyright
- X** notice must be maintained in any copy made.
- X**
- X** Use of this software constitutes acceptance for use in an AS IS
- X** condition. There are NO warranties with regard to this software.
- X** In no event shall the author be liable for any damages whatsoever
- X** arising out of or in connection with the use or performance of this
- X** software. Any use of this software is at the user's own risk.
- X**
- X** If you make modifications to this software that you feel
- X** increases it usefulness for the rest of the community, please
- X** email the changes, enhancements, bug fixes as well as any and
- X** all ideas to me. This software is going to be maintained and
- X** enhanced as deemed necessary by the community.
- X*/
- X/* termcap to terminfo conversion */
- X
- X#ifdef MAIN
- X#define EXTERN
- X#else
- X#define EXTERN extern
- X#endif
- X
- Xtypedef char *CHARSTAR;
- X
- XEXTERN char
- X auto_left_margin, auto_right_margin, no_esc_ctlc,
- X ceol_standout_glitch, eat_newline_glitch, erase_overstrike,
- X generic_type, hard_copy, has_meta_key, has_status_line,
- X insert_null_glitch, memory_above, memory_below, move_insert_mode,
- X move_standout_mode, over_strike, status_line_esc_ok,
- X dest_tabs_magic_smso, tilde_glitch, transparent_underline, xon_xoff,
- X needs_xon_xoff, prtr_silent, hard_cursor, non_rev_rmcup, no_pad_char,
- X non_dest_scroll_region, can_change, back_color_erase,
- X hue_lightness_saturation, col_addr_glitch, cr_cancels_micro_mode,
- X has_print_wheel, row_addr_glitch, semi_auto_right_margin,
- X cpi_changes_res, lpi_changes_res, physical_tabs;
- X
- XEXTERN int
- X columns, init_tabs, lines, lines_of_memory, magic_cookie_glitch,
- X padding_baud_rate, virtual_terminal, width_status_line, num_labels,
- X label_height, label_width, max_attributes, maximum_windows, max_colors,
- X max_pairs, no_color_video, buffer_capacity, dot_vert_spacing,
- X dot_horz_spacing, max_micro_address, max_micro_jump, micro_char_size,
- X micro_line_size, number_of_pins, output_res_char, output_res_line,
- X output_res_horz_inch, output_res_vert_inch, print_rate, wide_char_size;
- X
- XEXTERN CHARSTAR
- X back_tab, bell, carriage_return, change_scroll_region, clear_all_tabs,
- X clear_screen, clr_eol, clr_eos, column_address, command_character,
- X cursor_address, cursor_down, cursor_home, cursor_invisible,
- X cursor_left, cursor_mem_address, cursor_normal, cursor_right,
- X cursor_to_ll, cursor_up, cursor_visible, delete_character, delete_line,
- X dis_status_line, down_half_line, enter_alt_charset_mode,
- X enter_blink_mode, enter_bold_mode, enter_ca_mode, enter_delete_mode,
- X enter_dim_mode, enter_insert_mode, enter_secure_mode,
- X enter_protected_mode, enter_reverse_mode, enter_standout_mode,
- X enter_underline_mode, erase_chars, exit_alt_charset_mode,
- X exit_attribute_mode, exit_ca_mode, exit_delete_mode, exit_insert_mode,
- X exit_standout_mode, exit_underline_mode, flash_screen, form_feed,
- X from_status_line, init_1string, init_2string, init_3string, init_file,
- X insert_character, insert_line, insert_padding, key_backspace,
- X key_catab, key_clear, key_ctab, key_dc, key_dl, key_down, key_eic,
- X key_eol, key_eos, key_f0, key_f1, key_f10, key_f2, key_f3, key_f4,
- X key_f5, key_f6, key_f7, key_f8, key_f9, key_home, key_ic, key_il,
- X key_left, key_ll, key_npage, key_ppage, key_right, key_sf, key_sr,
- X key_stab, key_up, keypad_local, keypad_xmit, lab_f0, lab_f1, lab_f10,
- X lab_f2, lab_f3, lab_f4, lab_f5, lab_f6, lab_f7, lab_f8, lab_f9,
- X meta_off, meta_on, newline, pad_char, parm_dch, parm_delete_line,
- X parm_down_cursor, parm_ich, parm_index, parm_insert_line,
- X parm_left_cursor, parm_right_cursor, parm_rindex, parm_up_cursor,
- X pkey_key, pkey_local, pkey_xmit, print_screen, prtr_off, prtr_on,
- X repeat_char, reset_1string, reset_2string, reset_3string, reset_file,
- X restore_cursor, row_address, save_cursor, scroll_forward,
- X scroll_reverse, set_attributes, set_tab, set_window, tab,
- X to_status_line, underline_char, up_half_line, init_prog, key_a1,
- X key_a3, key_b2, key_c1, key_c3, prtr_non, char_padding, acs_chars,
- X plab_norm, key_btab, enter_xon_mode, exit_xon_mode, enter_am_mode,
- X exit_am_mode, xon_character, xoff_character, ena_acs, label_on,
- X label_off, key_beg, key_cancel, key_close, key_command, key_copy,
- X key_create, key_end, key_enter, key_exit, key_find, key_help, key_mark,
- X key_message, key_move, key_next, key_open, key_options, key_previous,
- X key_print, key_redo, key_reference, key_refresh, key_replace,
- X key_restart, key_resume, key_save, key_suspend, key_undo, key_sbeg,
- X key_scancel, key_scommand, key_scopy, key_screate, key_sdc, key_sdl,
- X key_select, key_send, key_seol, key_sexit, key_sfind, key_shelp,
- X key_shome, key_sic, key_sleft, key_smessage, key_smove, key_snext,
- X key_soptions, key_sprevious, key_sprint, key_sredo, key_sreplace,
- X key_sright, key_srsume, key_ssave, key_ssuspend, key_sundo,
- X req_for_input, key_f11, key_f12, key_f13, key_f14, key_f15, key_f16,
- X key_f17, key_f18, key_f19, key_f20, key_f21, key_f22, key_f23, key_f24,
- X key_f25, key_f26, key_f27, key_f28, key_f29, key_f30, key_f31, key_f32,
- X key_f33, key_f34, key_f35, key_f36, key_f37, key_f38, key_f39, key_f40,
- X key_f41, key_f42, key_f43, key_f44, key_f45, key_f46, key_f47, key_f48,
- X key_f49, key_f50, key_f51, key_f52, key_f53, key_f54, key_f55, key_f56,
- X key_f57, key_f58, key_f59, key_f60, key_f61, key_f62, key_f63, clr_bol,
- X clear_margins, set_left_margin, set_right_margin, label_format,
- X set_clock, display_clock, remove_clock, create_window, goto_window,
- X hangup, dial_phone, quick_dial, tone, pulse, flash_hook, fixed_pause,
- X wait_tone, user0, user1, user2, user3, user4, user5, user6, user7,
- X user8, user9, orig_pair, orig_colors, initialize_color,
- X initialize_pair, set_color_pair, set_foreground, set_background,
- X change_char_pitch, change_line_pitch, change_res_horz, change_res_vert,
- X define_char, enter_doublewide_mode, enter_draft_quality,
- X enter_italics_mode, enter_leftward_mode, enter_micro_mode,
- X enter_near_letter_quality, enter_normal_quality, enter_shadow_mode,
- X enter_subscript_mode, enter_superscript_mode, enter_upward_mode,
- X exit_doublewide_mode, exit_italics_mode, exit_leftward_mode,
- X exit_micro_mode, exit_shadow_mode, exit_subscript_mode,
- X exit_superscript_mode, exit_upward_mode, micro_column_address,
- X micro_down, micro_left, micro_right, micro_row_address, micro_up,
- X order_of_pins, parm_down_micro, parm_left_micro, parm_right_micro,
- X parm_up_micro, select_char_set, set_bottom_margin,
- X set_bottom_margin_parm, set_left_margin_parm, set_right_margin_parm,
- X set_top_margin, set_top_margin_parm, start_bit_image,
- X start_char_set_def, stop_bit_image, stop_char_set_def,
- X subscript_characters, superscript_characters, these_cause_cr,
- X zero_motion, char_set_names, reset_string;
- X
- X#ifdef TC
- XEXTERN CHARSTAR cursor_on;
- XEXTERN CHARSTAR color_terminal;
- X#endif
- X
- X#ifdef XENIX
- XEXTERN CHARSTAR key_char_left;
- XEXTERN CHARSTAR key_change_window;
- XEXTERN CHARSTAR key_send;
- XEXTERN CHARSTAR key_Home;
- XEXTERN CHARSTAR key_line_delete;
- XEXTERN CHARSTAR key_linefeed;
- XEXTERN CHARSTAR key_next_unlocked_cell;
- XEXTERN CHARSTAR key_start_print;
- XEXTERN CHARSTAR key_page_down;
- XEXTERN CHARSTAR key_page_up;
- XEXTERN CHARSTAR key_stop_print;
- XEXTERN CHARSTAR key_recalc;
- XEXTERN CHARSTAR key_toggle_ref;
- XEXTERN CHARSTAR key_return;
- XEXTERN CHARSTAR key_up_arrow;
- XEXTERN CHARSTAR key_word_left;
- XEXTERN CHARSTAR key_word_right;
- X#endif
- X
- X#define MAX_STRINGS 355
- END_OF_FILE
- if test 7528 -ne `wc -c <'bsd.h'`; then
- echo shar: \"'bsd.h'\" unpacked with wrong size!
- fi
- # end of 'bsd.h'
- fi
- if test -f 'capcomp.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'capcomp.c'\"
- else
- echo shar: Extracting \"'capcomp.c'\" \(4641 characters\)
- sed "s/^X//" >'capcomp.c' <<'END_OF_FILE'
- X/*
- X** This software is Copyright (c) 1991 by Daniel Weaver.
- X**
- X** Permission is hereby granted to copy, distribute or otherwise
- X** use any part of this package as long as you do not try to make
- X** money from it or pretend that you wrote it. This copyright
- X** notice must be maintained in any copy made.
- X**
- X** Use of this software constitutes acceptance for use in an AS IS
- X** condition. There are NO warranties with regard to this software.
- X** In no event shall the author be liable for any damages whatsoever
- X** arising out of or in connection with the use or performance of this
- X** software. Any use of this software is at the user's own risk.
- X**
- X** If you make modifications to this software that you feel
- X** increases it usefulness for the rest of the community, please
- X** email the changes, enhancements, bug fixes as well as any and
- X** all ideas to me. This software is going to be maintained and
- X** enhanced as deemed necessary by the community.
- X*/
- X/* compare 2 termcaps */
- X
- X/*
- X Usage:
- X capcomp [ -A termcap-file ] [ -B termcap-file ] [ -p ]
- X [ termname ] [ termname ]
- X
- X*/
- X
- X#include <stdio.h>
- X
- X#ifdef TC
- X#define tgetent tcgetent
- X#endif
- X
- Xextern char *getenv();
- X
- Xchar c1[4096], c2[4096]; /* termcap buffers */
- Xchar *s1[128][128], *s2[128][128]; /* sorted capabilities */
- Xchar buf[8192];
- Xint bp, dup;
- X
- Xint ignore_pad;
- Xchar Afile[512], Bfile[512];
- Xchar Aterm[512], Bterm[512];
- X
- Xextern char **environ;
- X
- Xchar termfile[512];
- Xchar *new_env[2] = {termfile, 0};
- X
- Xsort(a, b, name)
- Xchar *a, *name;
- Xchar **b;
- X{
- X int i;
- X char *s, *t;
- X
- X for (s = a; *s != ':'; s++) /* scan past name */
- X if (!*s) return;
- X if (dup) printf("\n");
- X dup = 0;
- X for (s++; *s; s++) {
- X while (*s == ' ' || *s == '\t') s++;
- X if (*s == ':') continue; /* ignore null entries */
- X i = *s * 128;
- X i += *++s;
- X if (!*s) return;
- X if (b[i]) {
- X if (dup++ == 0)
- X printf("%s multiple definitions: ", name);
- X else printf(", ");
- X printf("%c%c", i / 128, i & 127);
- X /* trash the second entry */
- X for ( ; *s && *s != ':'; s++);
- X if (!*s) return;
- X continue;
- X }
- X if (!*++s) return;
- X if (*s == ':') { /* boolean */
- X b[i] = "on";
- X continue;
- X }
- X if (*s++ == '=' && ignore_pad) /* trash the pad count */
- X {
- X for ( ; *s >= '0' && *s <= '9'; s++);
- X if (*s == '*') s++; /* repeat factor */
- X }
- X t = b[i] = &buf[bp];
- X for ( ; *s && *s != ':'; s++)
- X buf[bp++] = *s;
- X buf[bp++] = '\0';
- X if (!*s) return;
- X i = 0;
- X for ( ; *t; t++) {
- X if (i == '\\')
- X switch (*t) {
- X case 'b': *t = '\b' + '@'; t[-1] = '^'; break;
- X case 'f': *t = '\f' + '@'; t[-1] = '^'; break;
- X case 'n': *t = '\n' + '@'; t[-1] = '^'; break;
- X case 'r': *t = '\r' + '@'; t[-1] = '^'; break;
- X case 't': *t = '\t' + '@'; t[-1] = '^'; break;
- X default:
- X i = 0; continue;
- X }
- X i = *t;
- X }
- X }
- X}
- X
- X
- Xsend(s)
- Xchar *s;
- X{
- X int ch;
- X
- X while (ch = (*s & 0xff)) {
- X if (ch == 127) printf("^?");
- X else
- X if (ch > 128) printf("\\%o", *s);
- X else
- X if (ch >= ' ') printf("%c", *s);
- X else printf("^%c", *s + '@');
- X s++;
- X }
- X}
- X
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar **argv;
- X{
- X int i, j;
- X char *s, *t;
- X
- X if (argc < 2) {
- X printf("Usage: capcomp [-A termcap-file] [-B termcap-file] [-p] [termname] [termname]\n");
- X exit(1);
- X }
- X /* set up defaults */
- X if (s = getenv("TERM")) {
- X strcpy(Aterm, s);
- X strcpy(Bterm, s);
- X }
- X if ((s = getenv("TERMCAP")) && *s == '/') {
- X strcpy(Afile, s);
- X strcpy(Bfile, s);
- X }
- X else {
- X strcpy(Afile, "/etc/termcap");
- X strcpy(Bfile, Afile);
- X }
- X ignore_pad = 0;
- X /* scan the input arguments */
- X for (i = j = 1; i < argc; i++) {
- X if (!strcmp(argv[i], "-A") && ++i < argc) {
- X strcpy(Afile, argv[i]);
- X }
- X else
- X if (!strcmp(argv[i], "-B") && ++i < argc) {
- X strcpy(Bfile, argv[i]);
- X }
- X else
- X if (!strcmp(argv[i], "-p")) {
- X ignore_pad = 1;
- X }
- X else
- X if (j == 1) {
- X strcpy(Aterm, argv[i]);
- X j++;
- X }
- X else strcpy(Bterm, argv[i]);
- X }
- X printf("%s %s <--> %s %s with%s pads\n",
- X Afile, Aterm, Bfile, Bterm, ignore_pad ? "out" : "");
- X
- X environ = new_env;
- X sprintf(termfile, "TERMCAP=%s", Afile);
- X if (tgetent(c1, Aterm) <= 0) {
- X printf("Unable to find %s\n", Aterm);
- X exit(1);
- X }
- X
- X sprintf(termfile, "TERMCAP=%s", Bfile);
- X if (tgetent(c2, Bterm) <= 0) {
- X printf("Unable to find %s\n", Bterm);
- X exit(1);
- X }
- X
- X sort(c1, s1, Aterm);
- X sort(c2, s2, Bterm);
- X if (dup) printf("\n");
- X for (i = 0; i < 128; i++)
- X for (j = 0; j < 128; j++) {
- X s = s1[i][j] ? s1[i][j] : "";
- X t = s2[i][j] ? s2[i][j] : "";
- X if (strcmp(s, t)) {
- X printf("%20s %c%c %s\n", s, i, j, t);
- X }
- X }
- X exit(0);
- X}
- END_OF_FILE
- if test 4641 -ne `wc -c <'capcomp.c'`; then
- echo shar: \"'capcomp.c'\" unpacked with wrong size!
- fi
- # end of 'capcomp.c'
- fi
- if test -f 'color.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'color.c'\"
- else
- echo shar: Extracting \"'color.c'\" \(18610 characters\)
- sed "s/^X//" >'color.c' <<'END_OF_FILE'
- X/*
- X** This software is Copyright (c) 1991 by Daniel Weaver.
- X**
- X** Permission is hereby granted to copy, distribute or otherwise
- X** use any part of this package as long as you do not try to make
- X** money from it or pretend that you wrote it. This copyright
- X** notice must be maintained in any copy made.
- X**
- X** Use of this software constitutes acceptance for use in an AS IS
- X** condition. There are NO warranties with regard to this software.
- X** In no event shall the author be liable for any damages whatsoever
- X** arising out of or in connection with the use or performance of this
- X** software. Any use of this software is at the user's own risk.
- X**
- X** If you make modifications to this software that you feel
- X** increases it usefulness for the rest of the community, please
- X** email the changes, enhancements, bug fixes as well as any and
- X** all ideas to me. This software is going to be maintained and
- X** enhanced as deemed necessary by the community.
- X*/
- X/* color terminal tests */
- X
- X#include "curses.h"
- X#include "ted.h"
- X
- X#ifdef SVR3_2
- X
- Xextern struct mode_list alt_modes[];
- Xextern int mode_map[];
- X
- Xstruct color_table {
- X char *name;
- X int r, g, b;
- X int h, l, s;
- X} def_colors[8] = {
- X "black ", 0, 0, 0, 0, 0, 0,
- X "blue ", 0, 0, 1000, 330, 50, 100,
- X "green ", 0, 1000, 0, 240, 50, 100,
- X "cyan ", 0, 1000, 1000, 300, 50, 100,
- X "red ", 1000, 0, 0, 120, 50, 100,
- X "magenta", 1000, 0, 1000, 60, 50, 100,
- X "yellow ", 1000, 1000, 0, 180, 50, 100,
- X "white ", 1000, 1000, 1000, 0, 100, 0};
- X
- X#ifndef COLOR_BLACK
- X#define COLOR_BLACK 0
- X#define COLOR_BLUE 1
- X#define COLOR_GREEN 2
- X#define COLOR_CYAN 3
- X#define COLOR_RED 4
- X#define COLOR_MAGENTA 5
- X#define COLOR_YELLOW 6
- X#define COLOR_WHITE 7
- X#endif
- X
- X#define MAX_PAIR 256
- Xstatic int fg_color[MAX_PAIR] = {COLOR_BLACK, COLOR_BLUE, COLOR_GREEN,
- X COLOR_CYAN, COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE};
- Xstatic int bg_color[MAX_PAIR] = {COLOR_BLACK, COLOR_BLACK, COLOR_BLACK,
- X COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK};
- Xstatic int pairs_used;
- Xstatic int a_bright_color, bright_value;
- Xstatic int cookie_monster, color_step, colors_per_line;
- Xstatic int R, G, B;
- X
- Xstatic int
- Xcolor_trans(c)
- Xint c;
- X { /* translate or load the color */
- X int i;
- X
- X for (i = 0; i < pairs_used; i++) {
- X if (fg_color[i] == c) return i;
- X }
- X if (!can_change)
- X return 0;
- X if (pairs_used > max_colors || pairs_used >= MAX_PAIR)
- X {
- X pairs_used = 0;
- X ptextln("Ran out of colors");
- X }
- X fg_color[pairs_used] = c;
- X bg_color[pairs_used] = c;
- X if (hue_lightness_saturation)
- X putp(tparm(initialize_color, pairs_used,
- X def_colors[c].h, def_colors[c].l, def_colors[c].s));
- X else putp(tparm(initialize_color, pairs_used,
- X def_colors[c].r, def_colors[c].g, def_colors[c].b));
- X return pairs_used++;
- X }
- X
- X
- Xstatic void
- Xnew_color(fg, bg, hungry)
- Xint fg, bg, hungry;
- X { /* change the color to fg and bg. */
- X int i;
- X
- X if (hungry) eat_cookie();
- X if (set_foreground)
- X {
- X /* make sure black is zero */
- X (void) color_trans(COLOR_BLACK);
- X putp(tparm(set_foreground, color_trans(fg)));
- X putp(tparm(set_background, color_trans(bg)));
- X }
- X else /* set color pair */
- X {
- X for (i = 0; i < pairs_used; i++)
- X if (fg_color[i] == fg && bg_color[i] == bg) {
- X putp(tparm(set_color_pair, i));
- X if (hungry) eat_cookie();
- X return;
- X }
- X if (!can_change)
- X {
- X /* try to set just the foreground */
- X for (i = pairs_used - 1; i; i--)
- X if (fg_color[i] == fg) break;
- X putp(tparm(set_color_pair, i));
- X if (hungry) eat_cookie();
- X return;
- X }
- X if (pairs_used > max_pairs || pairs_used >= MAX_PAIR)
- X {
- X pairs_used = 0;
- X ptextln("Ran out of color pairs");
- X }
- X fg_color[pairs_used] = fg;
- X bg_color[pairs_used] = bg;
- X if (hue_lightness_saturation)
- X putp(tparm(initialize_pair, pairs_used,
- X def_colors[fg].h, def_colors[fg].l, def_colors[fg].s,
- X def_colors[bg].h, def_colors[bg].l, def_colors[bg].s));
- X else putp(tparm(initialize_pair, pairs_used,
- X def_colors[fg].r, def_colors[fg].g, def_colors[fg].b,
- X def_colors[bg].r, def_colors[bg].g, def_colors[bg].b));
- X putp(tparm(set_color_pair, pairs_used));
- X pairs_used++;
- X }
- X if (hungry) eat_cookie();
- X }
- X
- X
- Xstatic void
- Xset_color_step()
- X { /* set the color_step for the (ccc) display */
- X int i;
- X
- X for (i = 2; i < 1000; i++) {
- X if ((i * i * i) >= max_colors) break;
- X }
- X color_step = 1000 / (i - 1);
- X }
- X
- X
- Xstatic void
- Xrgb_2_hls(r, g, b, h, l, s)
- Xint r, g, b;
- Xint *h, *l, *s;
- X { /* convert RGB to HLS system */
- X int min, max, t;
- X
- X if ((min = g < r ? g : r) > b) min = b;
- X if ((max = g > r ? g : r) < b) max = b;
- X
- X /* calculate lightness */
- X *l = (min + max) / 20;
- X
- X if (min == max)
- X { /* black, white and all shades of gray */
- X *h = 0;
- X *s = 0;
- X return;
- X }
- X
- X /* calculate saturation */
- X if (*l < 50)
- X *s = ((max - min) * 100) / (max + min);
- X else *s = ((max - min) * 100) / (2000 - max - min);
- X
- X /* calculate hue */
- X if (r == max)
- X t = 120 + ((g - b) * 60) / (max - min);
- X else
- X if (g == max)
- X t = 240 + ((b - r) * 60) / (max - min);
- X else
- X t = 360 + ((r - g) * 60) / (max - min);
- X
- X *h = t % 360;
- X}
- X
- X
- Xstatic void
- Xsend_color(p, r, g, b)
- Xint p, r, g, b;
- X { /* send the initialize_color (initc) command */
- X int h, l, s;
- X
- X if (hue_lightness_saturation)
- X {
- X rgb_2_hls(r, g, b, &h, &l, &s);
- X putp(tparm(initialize_color, p, h, l, s));
- X }
- X else
- X putp(tparm(initialize_color, p, r, g, b));
- X }
- X
- X
- Xstatic void
- Xsend_pair(p, fr, fg, fb, br, bg, bb)
- Xint p, fr, fg, fb, br, bg, bb;
- X { /* send the initialize_pair (initp) command */
- X int fh, fl, fs, bh, bl, bs;
- X
- X if (hue_lightness_saturation)
- X {
- X rgb_2_hls(fr, fg, fb, &fh, &fl, &fs);
- X rgb_2_hls(br, bg, bb, &bh, &bl, &bs);
- X putp(tparm(initialize_pair, p, fh, fl, fs, bh, bl, bs));
- X }
- X else
- X putp(tparm(initialize_pair, p, fr, fg, fb, bb, bg, bb));
- X }
- X
- X
- Xstatic int
- Xload_palette(n)
- Xint n;
- X { /* load the color palette */
- X int rgb;
- X
- X for (;;) {
- X if (pairs_used >= n) return FALSE;
- X if (set_foreground)
- X {
- X if (pairs_used >= max_colors) return FALSE;
- X send_color(pairs_used, R, G, B);
- X rgb = R + G + B;
- X if (rgb > bright_value)
- X {
- X bright_value = rgb; a_bright_color = pairs_used;
- X }
- X }
- X else
- X {
- X if (pairs_used >= max_pairs) return FALSE;
- X if (pairs_used == 0)
- X send_pair(pairs_used, 1000, 1000, 1000, R, G, B);
- X else send_pair(pairs_used, R, G, B, R, G, B);
- X }
- X pairs_used++;
- X if ((B += color_step) > 1000)
- X {
- X B = 0;
- X if ((G += color_step) > 1000)
- X {
- X G = 0;
- X if ((R += color_step) > 1000) return TRUE;
- X }
- X }
- X }
- X }
- X
- X
- Xstatic int
- Xrainbow(n)
- Xint n;
- X { /* print the programable color display */
- X int i, c, d, palette_full, initial_pair;
- X static struct {
- X char *name;
- X char ch;
- X } splat[] = {
- X "Bg normal", ' ',
- X "Fg normal", ' ',
- X 0, 0};
- X
- X if (set_foreground ? pairs_used >= max_colors :
- X pairs_used >= max_pairs)
- X {
- X ptextln("New palette");
- X (void) wait_here();
- X initial_pair = pairs_used = 1;
- X bright_value = 0;
- X }
- X else
- X if (line_count + 3 >= lines)
- X {
- X (void) wait_here();
- X put_clear();
- X initial_pair = pairs_used = 1;
- X bright_value = 0;
- X n++;
- X }
- X else
- X {
- X initial_pair = pairs_used;
- X n += initial_pair;
- X }
- X palette_full = load_palette(n);
- X for (d = 0; splat[d].name; d++) {
- X c = splat[d].ch;
- X if (d == 1) put_mode(enter_reverse_mode);
- X for (i = initial_pair; i < n; i++) {
- X if (i >= pairs_used) break;
- X if (set_foreground)
- X {
- X if (i >= max_colors) break;
- X putp(tparm(set_foreground, i));
- X putp(tparm(set_background, i));
- X }
- X else
- X {
- X if (i >= max_pairs) break;
- X putp(tparm(set_color_pair, i));
- X }
- X putchp(c);
- X }
- X if (d == 1) put_mode(exit_attribute_mode);
- X
- X if (set_foreground)
- X {
- X putp(tparm(set_foreground, a_bright_color));
- X putp(tparm(set_background, 0));
- X }
- X else putp(tparm(set_color_pair, 0));
- X
- X put_str(" ");
- X put_str(splat[d].name);
- X put_crlf();
- X }
- X return palette_full;
- X }
- X
- X
- Xstatic void
- Xncv_display(m)
- Xint m;
- X { /* print the no_color_video (ncv) test line */
- X putchp('0' + m);
- X putchp(' ');
- X eat_cookie();
- X set_attr(1 << m);
- X sprintf(temp, "%-11s", alt_modes[m].name);
- X put_str(temp);
- X
- X new_color(COLOR_BLUE, COLOR_BLACK, TRUE);
- X put_str("blue");
- X
- X new_color(COLOR_BLACK, COLOR_GREEN, TRUE);
- X put_str("green");
- X
- X new_color(COLOR_WHITE, COLOR_BLACK, TRUE);
- X put_str(alt_modes[m].name);
- X eat_cookie();
- X set_attr(0);
- X put_crlf();
- X }
- X
- X
- Xstatic void
- Xdump_colors()
- X { /* display the colors in some estetic pattern */
- X static int xmap[8] = {0, 3, 4, 7, 1, 2, 5, 6};
- X int i, j, k, xi, xj, width, p, cs;
- X int found_one;
- X
- X cs = color_step <= 125 ? 125 : color_step;
- X width = (1000 / cs) + 1;
- X for (xi = 0; xi < 16; xi++) {
- X i = (xi & 8) ? xi ^ 15 : xi;
- X R = i * cs;
- X if (R <= 1000)
- X {
- X found_one = FALSE;
- X for (xj = 0; xj < 32; xj++) {
- X j = ((xj & 8) ? xj ^ 15 : xj) & 7;
- X k = xmap[((xi >> 1) & 4) + (xj >> 3)];
- X G = j * cs;
- X B = k * cs;
- X if (G <= 1000 && B <= 1000)
- X {
- X p = (k * width + j) * width + i;
- X if (set_background)
- X {
- X if (p >= max_colors) continue;
- X send_color(p, R, G, B);
- X putp(tparm(set_background, p));
- X }
- X else
- X {
- X if (p >= max_pairs) continue;
- X send_pair(p, R, G, B, R, G, B);
- X putp(tparm(set_color_pair, p));
- X }
- X found_one = TRUE;
- X putchp(' ');
- X putchp(' ');
- X }
- X }
- X if (found_one) put_crlf();
- X }
- X }
- X }
- X#endif
- X
- X
- Xvoid
- Xtest_color()
- X { /* test color attributes */
- X#ifdef SVR3_2
- X int i, j;
- X
- X if (stop_testing)
- X {
- X can_test("(colors)(pairs)(setb)(setf)(scp)(ncv)(bce)(ccc)");
- X can_test("(initc)(hls)(initp)(op)(oc)");
- X return;
- X }
- X
- X new_test(2);
- X if (max_colors <= 0 && max_pairs <= 0)
- X {
- X ptextln("This is not a color terminal. (colors) and (pairs) are missing.");
- X (void) wait_here();
- X return;
- X }
- X sprintf(temp, "This terminal can display %d colors and %d color pairs. (colors) (pairs)",
- X max_colors, max_pairs);
- X ptextln(temp);
- X if (set_foreground == NULL & set_color_pair == NULL)
- X {
- X ptextln("Both set foreground (setf) and set color pair (scp) are not present.");
- X if (!set_background)
- X ptextln("(setb) set background not present");
- X ptextln("Color testing terminated...");
- X return;
- X }
- X
- X maybe_wait(21);
- X /* initialize the color palette */
- X pairs_used = max_colors >= 8 ? 8 : max_colors;
- X if (can_change) putp(orig_colors);
- X putp(tparm(orig_pair));
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X
- X ptextln("\n(setf) (setb) (scp) The following colors are predefined:");
- X ptextln("\n Foreground Background");
- X put_crlf();
- X j = max_colors > 8 ? 8 : max_colors;
- X /* the black on white test is the same as the white on black test. */
- X for (i = 1; i < j; i++) {
- X putchp('0' + i);
- X putchp(' ');
- X sprintf(temp, " %s ", def_colors[i].name);
- X
- X new_color(i, COLOR_BLACK, TRUE);
- X put_str(temp);
- X
- X new_color(COLOR_BLACK, COLOR_BLACK, TRUE);
- X put_str(" ");
- X
- X new_color(COLOR_BLACK, i, TRUE);
- X put_str(temp);
- X
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X put_crlf();
- X }
- X
- X (void) wait_here();
- X
- X putln(" 0 1 2 3 4 5 6 7");
- X for (i = 0; i < 8; i++) {
- X j = pairs_used + 8;
- X if ((j > max_pairs || j >= MAX_PAIR) && can_change)
- X {
- X pairs_used = 0;
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X ptext("Ran out of color pairs");
- X (void) wait_here();
- X put_crlf();
- X }
- X putchp('0' + i);
- X for (j = 0; j < 8; j++) {
- X new_color(j, i, TRUE);
- X putchp('0' + i);
- X }
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X put_crlf();
- X }
- X (void) wait_here();
- X new_test(16);
- X ptextln("\nAccording to no_color_video (ncv), the following attributes should work correctly with color.\n");
- X set_attr(0);
- X ncv_display(0);
- X for (i = 1; i <= 9; i++)
- X if (((no_color_video >> (mode_map[i] - 1)) & 1) == 0)
- X ncv_display(mode_map[i]);
- X if (no_color_video & 0x3ff)
- X {
- X ptextln("\nThe following attributes should not work correctly with color. (ncv)\n");
- X for (i = 1; i <= 9; i++)
- X if ((no_color_video >> (mode_map[i] - 1)) & 1)
- X ncv_display(mode_map[i]);
- X }
- X i = wait_here();
- X if (i > ' ' & i <= 'z')
- X {
- X ptext("The following decimal values may be used to add or delete attributes to/from (ncv):");
- X for (i = 1; i <= 9; i++) {
- X sprintf(temp, " %d/%d", i, 1 << (i - 1));
- X ptext(temp);
- X }
- X put_crlf();
- X (void) wait_here();
- X }
- X new_color(COLOR_WHITE, COLOR_WHITE, FALSE);
- X put_clear();
- X put_newlines(2);
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X ptextln("If the two lines above are black then back_color_erase (bce) should be false.");
- X sprintf(temp, "(bce) is %s in the data base.", back_color_erase ? "true" : "false");
- X ptextln(temp);
- X (void) wait_here();
- X put_clear();
- X
- X /* color palette test */
- X if (can_change)
- X {
- X putp(orig_colors);
- X pairs_used = 0;
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X sprintf(temp, "Reloading colors (init%c) using %s method",
- X set_foreground ? 'c' : 'p',
- X hue_lightness_saturation ? "HLS" : "RGB");
- X ptextln(temp);
- X put_crlf();
- X j = max_colors > 7 ? 7 : max_colors;
- X /* redisplay the above test with reinitialized colors */
- X /* If these colors don't look right to you... */
- X for (i = 0; i < j; i++) {
- X sprintf(temp, " %s ", def_colors[i ^ 7].name);
- X
- X new_color(i ^ 7, COLOR_BLACK, TRUE);
- X put_str(temp);
- X
- X new_color(COLOR_BLACK, COLOR_BLACK, TRUE);
- X put_str(" ");
- X
- X new_color(COLOR_BLACK, i ^ 7, TRUE);
- X put_str(temp);
- X
- X new_color(COLOR_WHITE, COLOR_BLACK, FALSE);
- X put_crlf();
- X }
- X (void) wait_here();
- X
- X pairs_used = 0;
- X cookie_monster = 0;
- X if (magic_cookie_glitch > 0)
- X {
- X cookie_monster =
- X (set_foreground ? magic_cookie_glitch : 0) +
- X (set_background ? magic_cookie_glitch : 0) +
- X (set_color_pair ? magic_cookie_glitch : 0);
- X }
- X set_color_step();
- X colors_per_line = max_colors > max_pairs
- X ? max_pairs : max_colors;
- X j = (columns - 14) / (cookie_monster + 1);
- X if (colors_per_line > j)
- X {
- X colors_per_line = (j / i) * i;
- X }
- X
- X sprintf(temp, "RGB color step %d, cookies %d", color_step,
- X cookie_monster);
- X ptextln(temp);
- X
- X R = G = B = 0;
- X pairs_used = 0;
- X for (;;) {
- X if (rainbow(colors_per_line)) break;
- X }
- X (void) wait_here();
- X dump_colors();
- X (void) wait_here();
- X putp(orig_colors);
- X }
- X else ptextln("Terminal can not change colors (ccc)");
- X putp(tparm(orig_pair));
- X ptextln("End color tests");
- X (void) wait_here();
- X#endif
- X }
- END_OF_FILE
- if test 18610 -ne `wc -c <'color.c'`; then
- echo shar: \"'color.c'\" unpacked with wrong size!
- fi
- # end of 'color.c'
- fi
- if test -f 'makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile'\"
- else
- echo shar: Extracting \"'makefile'\" \(3005 characters\)
- sed "s/^X//" >'makefile' <<'END_OF_FILE'
- X# makefile for terminfo/termcap test program
- X#
- X# The following pre-processor variables may be set.
- X#
- X# TESTCAP Used to test termcaps insted of terminfo's.
- X# Generally, when this code is compiled on System V Unix
- X# the TESTCAP variable should not be set. BSD systems
- X# should usually set TESTCAP. BSD systems that have
- X# System V support libraries may omit the TESTCAP
- X# variable in order to test terminfo.
- X#
- X# XENIX If used with TESTCAP this option will test alternate
- X# character sets as defined by SCO XENIX.
- X#
- X# MV If used with TESTCAP this option will test alternate
- X# character sets as defined by Multi-View and Portfolio.
- X#
- X# TC If used with TESTCAP this option will test alternate
- X# character sets as defined by the Terminal Control
- X# package created by MainStream Systems, Winfield Kansas.
- X#
- X# LIBTC When used with the TC option, LIBTC forces calls to the
- X# TC library instead of libtermcap.a.
- X#
- X# SVR3 System V Releaes 3.1. Has alternate character set
- X# support.
- X#
- X# SVR3_2 System V Release 3.2. Has color and 8 bit support.
- X#
- X# SELECT Use this define if your operating system has the select
- X# system call.
- X#
- X# WAIT_MODE Use this define if your operating system cannot tell if
- X# a chracter is ready in the input queue. Funtion keys
- X# must be padded with blanks.
- X#
- X# If generated without pre-processor variables, a terminfo test
- X# program will be generated for System V Release 3.
- X
- XBINDIR=/usr/local/bin
- X
- X# PATH for .c and .h files
- XDIR=.
- X
- X# use for terminfo testing
- X#CFLAGS=-O -DSVR3_2 -DSELECT
- X# use for termcap testing
- X#CFLAGS=-O -DTESTCAP -DSELECT
- X# use for xenix termcap testing
- X#CFLAGS=-O -DTESTCAP -DXENIX
- X#
- XCFLAGS=-O -DTESTCAP -DSELECT
- X
- X# use this line for native mode
- XLDFLAGS=-lcurses -ltermcap
- X# Xenix compatable curses package is called xcurses in ATT Unix SVR3
- X# use this line for xenix compatibility
- X#LDFLAGS=-lxcurses -lxtermcap
- X
- XCMD=ted
- X
- XOFILES=charset.o color.o control.o crum.o fun.o getcaps.o modes.o\
- X output.o pad.o scan.o sysdep.o ted.o tparam.o
- X
- XCFILES=$(DIR)/charset.c $(DIR)/color.c $(DIR)/control.c $(DIR)/crum.c\
- X $(DIR)/fun.c $(DIR)/getcaps.c $(DIR)/modes.c $(DIR)/output.c\
- X $(DIR)/pad.c $(DIR)/scan.c $(DIR)/sysdep.c $(DIR)/ted.c\
- X $(DIR)/tparam.c
- X
- X#CFILES=$(OFILES:.o=.c)
- X
- X$(CMD) : $P $(OFILES)
- X $(CC) -g -o $(CMD) $(OFILES) $(LDFLAGS)
- X
- X# The "build" program is designed to write the bsd.h and getcaps.c
- X# files. This program will only link under System V, but the output
- X# may be run on any system.
- Xbuild : $(DIR)/build.c
- X $(CC) -g build.c -o build -lcurses -ltermcap
- X
- X$(OFILES) : $(DIR)/ted.h
- X
- Xlint :
- X lint -DTESTCAP $(CFILES)
- X
- Xclean :
- X rm -f $(OFILES)
- X
- Xtags : $(CFILES) $(DIR)/ted.h
- X ctags $(>)
- X
- Xinstall: $(CMD)
- X cp $(CMD) $(BINDIR)
- X
- Xlist : $(DIR)/ted.h $(CFILES)
- X for name in $(>) ; \
- X do \
- X ucb cat -n $$name | ucb pr -h "$$name" | ucb lpr ; \
- X done
- X
- X# archive a backup copy
- Xarch : $(DIR)/makefile $(DIR)/ted.h $(CFILES)
- X rm -f ted.a
- X ar q ted.a $(>)
- X
- Xcapcomp: $(DIR)/capcomp.c
- X cc $(CFLAGS) $(?) $(LDFLAGS) -o capcomp
- END_OF_FILE
- if test 3005 -ne `wc -c <'makefile'`; then
- echo shar: \"'makefile'\" unpacked with wrong size!
- fi
- # end of 'makefile'
- fi
- echo shar: End of archive 7 \(of 7\).
- cp /dev/null ark7isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 7 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-